package com.base.task.entity;

import com.base.task.BatchConstants;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.Map;

/**
 * @ Author     ：山水之间-wxs
 * @ Description：批次传参
 * @ Date       ：Created in 10:58 2021/11/4
 * @ Modified By：wxs
 * @ Version    ：1.0
 */
@Data
public class BatchParam {

    private String title;
    private Map<String, Object> param;
    private Integer threadMaxNum;
    private Integer queryMaxNum;
    private LocalDateTime currentDateTime = LocalDateTime.now();

    public BatchParam() {}

    public BatchParam(String title) {
        this.title = title;
    }

    public BatchParam(Integer threadMaxNum, Integer queryMaxNum) {
        this.threadMaxNum = threadMaxNum;
        this.queryMaxNum = queryMaxNum;
        valid();
    }

    public BatchParam(String title, Integer threadMaxNum, Integer queryMaxNum) {
        this.title = title;
        this.threadMaxNum = threadMaxNum;
        this.queryMaxNum = queryMaxNum;
        valid();
    }

    public BatchParam(String title, Map<String, Object> param, Integer threadMaxNum, Integer queryMaxNum) {
        this.title = title;
        this.param = param;
        this.threadMaxNum = threadMaxNum;
        this.queryMaxNum = queryMaxNum;
        valid();
    }

    public void valid() {
        if (this.getTitle() == null || "".equals(this.getTitle().trim())) {
            this.setTitle(BatchConstants.DEFUALT_TITLE);
        }
        if (this.getQueryMaxNum() == null || this.getQueryMaxNum() <= 0) {
            this.setQueryMaxNum(BatchConstants.QUERY_MAX_NUM);
        }
        if (this.getThreadMaxNum() == null || this.getThreadMaxNum() <= 0) {
            this.setThreadMaxNum(BatchConstants.THREAD_MAX_NUM);
        }
    }

    public void setBatchParam(BatchParam param) {
        this.setParam(param.getParam());
        this.setTitle(param.getTitle());
        this.setThreadMaxNum(param.getThreadMaxNum());
        this.setQueryMaxNum(param.getQueryMaxNum());
        this.setCurrentDateTime(param.getCurrentDateTime());
    }

}
